//
//  ShezhiViewController.m
//  XRSquare
//
//  Created by UaenaMo on 2018/8/14.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "ShezhiViewController.h"
#import "ShezhiTableViewCell.h"
#import "LoginViewController.h"
#import "ChangePasswordViewController.h"
#import "ChangePhoneViewController.h"
#import "FeedBackViewController.h"
@interface ShezhiViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView * contentTableView;
}
@end

@implementation ShezhiViewController

-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    self.navigationItem.title = @"设置";
    
    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    CGRect rectNav = self.navigationController.navigationBar.frame;
    

    contentTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, rectStatus.size.height + rectNav.size.height, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
    contentTableView.delegate = self;
    contentTableView.dataSource = self;
    contentTableView.tableFooterView = [UIView new];
    contentTableView.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
    [contentTableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];

    [self.view addSubview:contentTableView];
}

#pragma mark - tableview

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 5) {
        return 5;
    }
    else
    {
        return 50;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

        static NSString * identifer = @"identifer";
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifer];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifer];
        }
        cell.backgroundColor = [UIColor whiteColor];
        cell.textLabel.text = @"";
        cell.detailTextLabel.text = @"";
        cell.accessoryType = UITableViewCellAccessoryNone;

        if (indexPath.row == 0)
        {
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = @"修改密码";
        }
        else if (indexPath.row == 1)
        {
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = @"更换手机";
        }
        else if (indexPath.row == 2)
        {
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = @"意见反馈";
        }
        else if (indexPath.row == 3)
        {
            cell.textLabel.text = @"客服邮箱";
            cell.detailTextLabel.text = @"info@xrsquare.com";
        }
        else if (indexPath.row == 4)
        {
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = @"关于我们";
        }
        else if (indexPath.row == 5)
        {
            cell.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        }
        else
        {
            cell.textLabel.text = @"退出";
        }
        
        return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    self.tabBarController.tabBar.hidden = YES;
    if (indexPath.row == 0)
    {
//        [cell loadTitle:@"修改密码" content:nil arrow:YES];
        ChangePasswordViewController * changePassword = [[ChangePasswordViewController alloc]init];
        [self.navigationController pushViewController:changePassword animated:YES];
    }
    else if (indexPath.row == 1)
    {
//        [cell loadTitle:@"更换手机" content:nil arrow:YES];
        ChangePhoneViewController * changePassword = [[ChangePhoneViewController alloc]init];
        [self.navigationController pushViewController:changePassword animated:YES];
    }
    else if (indexPath.row == 2)
    {
//        [cell loadTitle:@"意见反馈" content:nil arrow:YES];
        FeedBackViewController * changePassword = [[FeedBackViewController alloc]init];
        [self.navigationController pushViewController:changePassword animated:YES];
    }
    else if (indexPath.row == 3)
    {
//        [cell loadTitle:@"客服邮箱" content:@"info@xrsquare.com" arrow:NO];
    }
    else if (indexPath.row == 4)
    {
//        [cell loadTitle:@"关于我们" content:nil arrow:YES];
        WebViewController * webview = [[WebViewController alloc]init];
        webview.url = @"https://app.xrsquare.com/about";
        [self.navigationController pushViewController:webview animated:YES];
    }
    else
    {
        [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"cookie"];
        NSArray*array = [[NSHTTPCookieStorage sharedHTTPCookieStorage]cookies];
        for(NSHTTPCookie*cookie in array)
        {
            [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie: cookie];
        }
        MMNavController * nav = [[MMNavController alloc]initWithRootViewController:[[LoginViewController alloc]init]];
        [UIApplication sharedApplication].keyWindow.rootViewController = nav;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
